package org.ykh.gmall.product.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.ykh.gmall.product.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.ykh.gmall.product.service.ManagerService;
import org.ykh.gmall.result.Result;

import java.util.List;


@RestController
@RequestMapping("/admin/product")
@Tag(name = "商品管理接口1",description = "商品管理接口2")
//@CrossOrigin
public class BaseManagerController {


    @Autowired
    private ManagerService managerService;


    /**
     * /admin/product/getAttrValueList/{attrId}
     * 根据平台属性Id 获取到平台属性值集合
     * @return
     */
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId ){

      BaseAttrInfo baseAttrInfo=  managerService.getAttrValueList(attrId);

      if(baseAttrInfo!=null){
          List<BaseAttrValue> attrValueList = baseAttrInfo.getAttrValueList();

          return Result.ok(attrValueList);
      }

     return Result.ok();

    }

    /**
     * 保存-修改平台属性
     *  /admin/product/saveAttrInfo
     * @return
     */
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody  BaseAttrInfo baseAttrInfo){


         managerService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    /**
     * 根据分类Id 获取平台属性集合
     * /admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id}
     * @param category1Id
     * @param category2Id
     * @param category3Id
     * @return
     */
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(@PathVariable Long category1Id,
                               @PathVariable Long category2Id,
                               @PathVariable Long category3Id
    ){


     List<BaseAttrInfo> baseAttrInfoList=   managerService.attrInfoList(category1Id,category2Id,category3Id);


        return Result.ok(baseAttrInfoList);
    }



    /**
     *  /admin/product/getCategory3/{category2Id}
     * 根据二级分类id获取三级分类数据
     * @param category2Id
     * @return
     */
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable Long category2Id ){


        List<BaseCategory3> category2List=managerService.getCategory3(category2Id);

        return Result.ok(category2List);
    }




    /**
     *  /admin/product/getCategory2/{category1Id}
     * 根据一级分类id获取二级分类数据
     * @param category1Id
     * @return
     */
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable Long category1Id ){


        List<BaseCategory2> category2List=managerService.getCategory2(category1Id);

        return Result.ok(category2List);
    }



    /**
     * 获取一级分类数据
     * admin/product/getCategory1
     * @return
     */
    @GetMapping("/getCategory1")
    @Operation(summary  = "获取一级分类数据")
    public Result getCategory1(){

        List<BaseCategory1> baseCategory1List=managerService.getCategory1();

        return Result.ok(baseCategory1List);
    }

}
